import { deleteCourseNodes, addOneCourseNode, lookNode, updateOneCourseNode } from '@/api/courseNode'

const getDefaultState = () => {}

const state = getDefaultState()

const mutations = {}

const actions = {
  // 条件查询
  async lookNode({ state }, courseNode) {
    return new Promise((resolve, reject) => {
      lookNode(courseNode)
        .then((response) => {
          resolve(response)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 添加一条课节
  async addOneCourseNode({ state }, courseNode) {
    return new Promise((resolve, reject) => {
      addOneCourseNode(courseNode)
        .then((response) => {
          resolve(response)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 修改课节
  async updateOneCourseNode({ state }, courseNode) {
    return new Promise((resolve, reject) => {
      updateOneCourseNode(courseNode)
        .then((response) => {
          resolve(response)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 批量删除课节
  async deleteCourseNodes({ state }, ids) {
    return new Promise((resolve, reject) => {
      deleteCourseNodes(ids)
        .then((response) => {
          resolve(response)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
}
